<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;

/* @var $model \app\models\Admin */
/* @var $checkAccess */
?>

<div class="admin-form">
    <?php $form = ActiveForm::begin([
        'id' => 'Admin',
        'options' => Yii::$app->request->isAjax ? ['class' => 'form-horizontal'] : '',
        'fieldConfig' => Yii::$app->request->isAjax ? [
            'template' => "{label}\n<div class=\"col-lg-9\">{input}\n{error}</div>",
            'labelOptions' => ['class' => 'col-lg-3 control-label']
        ] : ''
    ]); ?>

    <?= $form->field($model, 'username')->textInput(array_merge(['maxlength' => true], $model->isNewRecord ? [] : ['readonly' => 'readonly'])); ?>

    <?php if ($checkAccess && $model->id != Yii::$app->user->id): ?>
        <?= $form->field($model, 'gid')->dropDownList(\app\models\AdminGroup::getGroups()); ?>
    <?php endif; ?>

    <?php if($model->isNewRecord): ?>
        <?= $form->field($model, 'password')->passwordInput(['maxlength' => true]); ?>
        <?= $form->field($model, 'password2')->passwordInput(['maxlength' => true]); ?>
    <?php else: ?>
        <?= $form->field($model, 'newPwd')->passwordInput(['placeholder' => '不修改请留空', 'maxlength' => true]); ?>
        <?= $form->field($model, 'newPwd2')->passwordInput(['placeholder' => '不修改请留空', 'maxlength' => true]); ?>
    <?php endif; ?>

    <?= $form->field($model, 'author')->textInput(['maxlength' => true]); ?>

    <?= $form->field($model, 'email')->textInput(['maxlength' => true]); ?>

    <?php if(($checkAccess || $model->isNewRecord) && $model->id != Yii::$app->user->id): ?>
        <?= $form->field($model, 'status')->dropDownList(\app\models\Admin::$statusLabels); ?>
    <?php endif;; ?>

    <div class="form-group<?= Yii::$app->request->isAjax ? ' hidden' : ''; ?>">
        <?= Html::submitButton('保存', ['class' => 'btn btn-full']) ?>
    </div>

    <?php ActiveForm::end(); ?>

</div>
